package com.dynamixsoftware.printershare.data;

import java.util.Collections;
import java.util.Hashtable;
import java.util.Vector;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Printer {
	public Hashtable<String, String> capabilities;
	public String default_duplexMode;
	public String default_paper;
	public String default_printoutMode;
	public String default_tray;
	public String direct_address;
	public String[] drv_envp;
	public boolean drv_manual;
	public String drv_model;
	public String drv_name;
	public String drv_params;
	public Vector<DuplexMode> duplexModes;
	public String id;
	public String location;
	public String model;
	public boolean online;
	public Vector<Printer> otherServices;
	public User owner;
	public Vector<Paper> papers;
	public Vector<PrintoutMode> printoutModes;
	public String title;
	public Vector<Tray> trays;

	public void readFromXml(Element paramElement) {
		this.id = XmlUtil.getFirstNodeValue(paramElement, "public-id");
		this.online = "True".equals(paramElement.getAttribute("online"));
		this.location = XmlUtil.getFirstNodeValue(paramElement, "location");
		this.title = XmlUtil.getFirstNodeValue(paramElement, "title");
		this.model = XmlUtil.getFirstNodeValue(paramElement, "model");
		Element localElement1 = XmlUtil.getFirstElement(paramElement, "owner");
		if (localElement1 != null) {
			this.owner = new User();
			this.owner.readFromXml(localElement1);
		}
		Element localElement2 = XmlUtil.getFirstElement(paramElement, "details");
		this.capabilities = new Hashtable();
		Element localElement3 = XmlUtil.getFirstElement(localElement2, "capabilities");
		if (localElement3 != null) {
			NamedNodeMap localNamedNodeMap = localElement3.getAttributes();
			for (int i2 = 0; i2 < localNamedNodeMap.getLength(); i2++) {
				Node localNode = localNamedNodeMap.item(i2);
				this.capabilities.put(localNode.getNodeName(), localNode.getNodeValue());
			}
		}
		this.papers = new Vector();
		Element localElement4 = XmlUtil.getFirstElement(localElement2, "paper-formats");
		int i = 0;
		if (localElement4 != null) {
			this.default_paper = localElement4.getAttribute("default");
			NodeList localNodeList2 = localElement4.getElementsByTagName("paper");
			int n = localNodeList2.getLength();
			if (n == 0) {
				localNodeList2 = localElement4.getElementsByTagName("paper-format");
				n = localNodeList2.getLength();
			}
			for (int i1 = 0; i1 < n; i1++) {
				Element localElement7 = (Element) localNodeList2.item(i1);
				Paper localPaper = new Paper();
				localPaper.readFromXml(localElement7);
				this.papers.add(localPaper);
				if ((i == 0) && (localPaper.id.equals(this.default_paper))) {
					i = 1;
				}
			}
			Collections.sort(this.papers);
		}
		if (i == 0) {
			this.default_paper = "";
		}
		this.trays = new Vector();
		Element localElement5 = XmlUtil.getFirstElement(localElement2, "bins");
		int j = 0;
		if (localElement5 != null) {
			this.default_tray = localElement5.getAttribute("default");
			NodeList localNodeList1 = localElement5.getElementsByTagName("bin");
			int k = localNodeList1.getLength();
			for (int m = 0; m < k; m++) {
				Element localElement6 = (Element) localNodeList1.item(m);
				Tray localTray = new Tray();
				localTray.readFromXml(localElement6);
				this.trays.add(localTray);
				if ((j == 0) && (localTray.id.equals(this.default_tray))) {
					j = 1;
				}
			}
			Collections.sort(this.trays);
		}
		if (j == 0) {
			this.default_tray = "";
		}
		this.printoutModes = new Vector();
		PrintoutMode localPrintoutMode1 = new PrintoutMode();
		localPrintoutMode1.id = "0";
		localPrintoutMode1.name = "Default";
		localPrintoutMode1.resolution = "200";
		this.printoutModes.add(localPrintoutMode1);
		if ("1".equals(this.capabilities.get("color"))) {
			PrintoutMode localPrintoutMode2 = new PrintoutMode();
			localPrintoutMode2.id = "1";
			localPrintoutMode2.name = "Grayscale";
			localPrintoutMode2.resolution = "200";
			this.printoutModes.add(localPrintoutMode2);
			PrintoutMode localPrintoutMode3 = new PrintoutMode();
			localPrintoutMode3.id = "2";
			localPrintoutMode3.name = "Color";
			localPrintoutMode3.resolution = "200";
			this.printoutModes.add(localPrintoutMode3);
		}
		this.default_printoutMode = "0";
		this.duplexModes = new Vector();
		if ("1".equals(this.capabilities.get("duplex"))) {
			DuplexMode localDuplexMode1 = new DuplexMode();
			localDuplexMode1.id = "1";
			localDuplexMode1.name = "On";
			this.duplexModes.add(localDuplexMode1);
		}
		DuplexMode localDuplexMode2 = new DuplexMode();
		localDuplexMode2.id = "0";
		localDuplexMode2.name = "Off";
		this.duplexModes.add(localDuplexMode2);
		this.default_duplexMode = "0";
	}
}